home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PASCAL / 0391B.ZIP / KEYDEFS.ARC / KEYDEMO.PAS < prev   
Pascal/Delphi Source File  |  1986-03-11  |  5KB  |  165 lines

  1. {***********************************************
  2. *                                              *
  3. *  Keyboard Definitions Demonstration Program  *
  4. *                                              *
  5. *            by Richard R. Rebouche            *
  6. *                                              *
  7. *              UpDate:  03/10/86               *
  8. *                                              *
  9. ***********************************************}
  10.  
  11.  
  12. {$I Keydefs.Inc}
  13.  
  14.  
  15. {*****************************************************
  16. *                                                    *
  17. *  Global Constant, Type, and Variable declarations  *
  18. *                                                    *
  19. *****************************************************}
  20.  
  21. Const Term_Height = 25;
  22.       Term_Width  = 80;
  23.  
  24. Type  Str02 = String[02];
  25.  
  26. Var   C, Window_Top, Line_Count : Integer;
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. {*************************************
  34. *                                    *
  35. *  Utility Functions and Procedures  *
  36. *                                    *
  37. *************************************}
  38.  
  39.  
  40. { Function:  Return a byte value as two hexadecimal digits. }
  41.  
  42. Function Hex_Value (N : Byte) : Str02;
  43.  
  44. Const  H : Array [0..15] of Char = '0123456789ABCDEF';
  45.  
  46. Begin
  47.   Hex_Value := H[N Div 16] + H[N Mod 16];
  48. End;
  49.  
  50.  
  51.  
  52.  
  53. { Procedure:  Print the introductory text for the demonstration. }
  54.  
  55. Procedure Print_Intro;
  56.  
  57. Begin
  58.   WriteLn;
  59.   WriteLn  ('*** Key Definition Demo ***');
  60.   WriteLn;
  61.   WriteLn  ('Enter special keys (like Alt-F1) from the keyboard.');
  62.   WriteLn  ('The program will print the token returned and a');
  63.   WriteLn  ('description of the key that was pressed.');
  64.   WriteLn;
  65.   WriteLn  ('Press the ESCAPE key to stop the program.');
  66.   WriteLn;
  67.   WriteLn;
  68.   Line_Count := 11;    { 10 Lines + 1 to compensate for behavior at line #25 }
  69. End;
  70.  
  71.  
  72.  
  73.  
  74.  
  75. { Procedure:  Print a description of a key based on its token value.  }
  76. {             Under normal circumstances one would not need (or want) }
  77. {             to implement key trapping on this scale.                }
  78.  
  79.  
  80. Procedure Print_Key_Desc (I : Integer);
  81.  
  82. Type Template  = Array [1..12] of Char;
  83.  
  84. Const Row_1 : Template = '1234567890-=';       { These are for the ALT-char }
  85.       Row_2 : Template = 'QWERTYUIOP  ';       { types of keystrokes        }
  86.       Row_3 : Template = 'ASDFGHJKL   ';
  87.       Row_4 : Template = 'ZXCVBNM     ';
  88.  
  89. Begin
  90.   Case I of
  91.  
  92.     Esc_Key            : Write ('Escape Key');
  93.     Tab_Key            : Write ('Tab Key');
  94.     Shft_Tab           : Write ('Shifted Tab Key');
  95.     Back_Del           : Write ('Back Arrow');
  96.     Return             : Write ('Return Key');
  97.     Space              : Write ('Space Bar');
  98.     Ins_Key            : Write ('Insert Key');
  99.     Del_Key            : Write ('Delete Key');
  100.  
  101.     Home_Key           : Write ('Home Key');
  102.     Ctrl_Home          : Write ('Control Home');
  103.     End_Key            : Write ('End Key');
  104.     Ctrl_End           : Write ('Control End');
  105.     PgUp               : Write ('Page Up Key');
  106.     Ctrl_PgUp          : Write ('Control Page Up');
  107.     PgDn               : Write ('Page Down Key');
  108.     Ctrl_PgDn          : Write ('Control Page Down');
  109.     Up_Key             : Write ('Up Arrow');
  110.     Down_Key           : Write ('Down Arrow');
  111.     Left_Key           : Write ('Left Arrow');
  112.     Ctrl_Left          : Write ('Control Left Arrow');
  113.     Right_Key          : Write ('Right Arrow');
  114.     Ctrl_Right         : Write ('Control Right Arrow');
  115.  
  116.           0..31        : Write ('Control "', Chr(I+64), '"');
  117.          32..255       : Write ('Character "', Chr(I), '"');
  118.  
  119.          F1..F10       : Write ('Function '          , I -      F1 + 1);
  120.     Shft_F1..Shft_F10  : Write ('Shift Function '    , I - Shft_F1 + 1);
  121.     Ctrl_F1..Ctrl_F10  : Write ('Control Function '  , I - Ctrl_F1 + 1);
  122.      Alt_F1..Alt_F10   : Write ('Alternate Function ', I -  Alt_F1 + 1);
  123.       Alt_1..Alt_Equal : Write ('Alternate ',    Row_1[I  - Alt_1  + 1]);
  124.       Alt_Q..Alt_P     : Write ('Alternate ',    Row_2[I  - Alt_Q  + 1]);
  125.       Alt_A..Alt_L     : Write ('Alternate ',    Row_3[I  - Alt_A  + 1]);
  126.       Alt_Z..Alt_M     : Write ('Alternate ',    Row_4[I  - Alt_Z  + 1]);
  127.  
  128.     Else                 Write ('An unidentified special key.');
  129.   End;
  130. End;
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. {**********************
  138. *                     *
  139. *  Main program body  *
  140. *                     *
  141. **********************}
  142.  
  143.  
  144. Begin
  145.   Print_Intro;                   { Display introductory text and }
  146.   C := 0;                        { initialize variables/counters }
  147.   Window_Top := Line_Count;
  148.  
  149.   While C <> Esc_Key do          { Loop until user presses ESCAPE }
  150.     Begin
  151.       Write ('Press a Key:  ');                         { Read the keystroke }
  152.       C := GetKey;
  153.  
  154.       Write ('$', Hex_Value(Hi(C)), Hex_Value(Lo(C)));  { Echo back to user  }
  155.       Write ('    Description:  ');
  156.       Print_Key_Desc(C);
  157.       WriteLn;
  158.  
  159.       Line_Count := Line_Count + 1;                     { Window to keep the }
  160.       If Line_Count = Term_Height then                  { text on the screen }
  161.         Window (1, Window_Top, Term_Width, Term_Height);
  162.     End;
  163. End.
  164.  
  165.